﻿using Microsoft.EntityFrameworkCore;
using Abp.Zero.EntityFrameworkCore;
using AbpBuild.Authorization.Roles;
using AbpBuild.Authorization.Users;
using AbpBuild.MultiTenancy;
using AbpBuild.LawManage;

using AbpBuild.BaseData;
using Abp.Dependency;
using AbpBuild.WenShu;

namespace AbpBuild.EntityFrameworkCore
{
    public class AbpBuildDbContext : AbpZeroDbContext<Tenant, Role, User, AbpBuildDbContext>
    {
        /* Define a DbSet for each entity of the application */
        
        public AbpBuildDbContext(DbContextOptions<AbpBuildDbContext> options)
            : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            //builder.Entity<Law>((entityBuilder) =>
            //{
            //    // 重命名字段 - 映射到数据库
            //    entityBuilder.Property(o => o.Id).HasColumnName("LawID");
            //});
            //builder.Entity<LawDetail>((entityBuilder) =>
            //{
            //    // 重命名字段 - 映射到数据库
            //    entityBuilder.Property(o => o.Id).HasColumnName("ContentId");
            //});
            //builder.Entity<Role>((entityBuilder) =>
            //{
            //    // 忽略字段 - 不映射到数据库
            //    entityBuilder.Ignore(o => o.Id);
            //});




            builder.Entity<LawjudgeProcess>(entity =>
            {
                entity.HasOne(d => d.parentLawjudgeProcess)
                    .WithMany(p => p.childLawjudgeProcess)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.pid)
                    .HasConstraintName("FK_LawjudgeProcess_LawjudgeProcess");
            });

            builder.Entity<caseReason>(entity =>
            {
                entity.HasOne(d => d.parentCaseReason)
                    .WithMany(p => p.childCasereasons)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.parent)
                    .HasConstraintName("FK_caseReason_Person");
            });

            builder.Entity<LawType>(entity =>
            {
                entity.HasOne(d => d.parentLawType)
                    .WithMany(p => p.childLawType)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.pid)
                    .HasConstraintName("FK_LawType_LawType");
            });

            builder.Entity<LawAuthority>(entity =>
            {
                entity.HasOne(d => d.parentLawAuthority)
                    .WithMany(p => p.childLawAuthority)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.pid)
                    .HasConstraintName("FK_LawAuthority_LawAuthority");
            });

            builder.Entity<Laweff_level>(entity =>
            {
                entity.HasOne(d => d.parentLaweff_level)
                    .WithMany(p => p.childLaweff_level)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.pid)
                    .HasConstraintName("FK_Laweff_level_Laweff_level");
            });
            builder.Entity<LawDXtype>(entity =>
            {
                entity.HasOne(d => d.parentLawDXtype)
                    .WithMany(p => p.childLawDXtype)
                    .HasPrincipalKey(p => p.Id)
                    .HasForeignKey(d => d.pid)
                    .HasConstraintName("FK_LawDXtype_LawDXtype");
            });


            //
 
        }

        public virtual DbSet<LawRecord> LawRecords { get; set; }
        public virtual DbSet<LawRecordOther> LawRecordOthers { get; set; }

        public virtual DbSet<changemima> changemimas { get; set; }

        public virtual DbSet<LawjudgeProcess> LawjudgeProcess { get; set; }
        public virtual DbSet<LawDXtype> LawDXtypes { get; set; }

        public virtual DbSet<caseReason> caseReasons { get; set; }
 

        public virtual DbSet<LawAuthority> LawAuthoritys { get; set; }
        public virtual DbSet<LawType> LawTypes { get; set; }
        public virtual DbSet<Laweff_level> Laweff_levels { get; set; }



        //

        public virtual DbSet<company> companys { get; set; }
        public virtual DbSet<courtFullName> courtfullnames { get; set; }
        public virtual DbSet<LawKeyWords> LawKeyWordss { get; set; }
        public virtual DbSet<courtJuger> courtJugers { get; set; }
        public virtual DbSet<lvshishiwusuo> lvshishiwusuos { get; set; }
        public virtual DbSet<lvshi> lvshis { get; set; }

    }
}
